package com.mytrip;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Hashtable;
import java.util.Iterator;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;

import com.mytrip.util.Constant;
import com.mytrip.util.TongchengUtil;

public class TestTongcheng{
	public static void main(String[] args) throws Exception{
		// test2();
		// System.out.println(getAreaBizListByCityId("321"));
		// System.out.println(getAreaListByCityId("321"));
		// System.out.println(getChainHotelList("321"));
		// System.out.println(getHotelList("321"));
		// System.out.println(getHotelDetail("7870"));
		// System.out.println(getHotelRooms("7870"));
		System.out.println(getOrderList("13566001155"));
	}

	private static void test2() throws Exception{

		// 省
		String provinceStr = "<?xml version=\"1.0\" encoding=\"utf-8\"?><response><header><actionCode>1</actionCode><rspType>0</rspType><rspCode>0000</rspCode><rspDesc><![CDATA[查询成功]]></rspDesc><digitalSign /><rspTime>2012-03-21 22:42:06.203</rspTime></header><body><provinceList totalCount=\"34\"><province><id>2</id><name>安徽</name><enName>AnHui</enName><prefixLetter>A</prefixLetter></province><province><id>3</id><name>北京</name><enName>BeiJing</enName><prefixLetter>B</prefixLetter></province><province><id>4</id><name>福建</name><enName>FuJian</enName><prefixLetter>F</prefixLetter></province><province><id>5</id><name>甘肃</name><enName>GanSu</enName><prefixLetter>G</prefixLetter></province><province><id>6</id><name>广东</name><enName>GuangDong</enName><prefixLetter>G</prefixLetter></province><province><id>7</id><name>广西</name><enName>GuangXi</enName><prefixLetter>G</prefixLetter></province><province><id>8</id><name>贵州</name><enName>GuiZhou</enName><prefixLetter>G</prefixLetter></province><province><id>9</id><name>海南</name><enName>HaiNan</enName><prefixLetter>H</prefixLetter></province><province><id>10</id><name>河北</name><enName>HeBei</enName><prefixLetter>H</prefixLetter></province><province><id>11</id><name>河南</name><enName>HeNan</enName><prefixLetter>H</prefixLetter></province><province><id>12</id><name>黑龙江</name><enName>HeiLongJiang</enName><prefixLetter>H</prefixLetter></province><province><id>13</id><name>湖北</name><enName>HuBei</enName><prefixLetter>H</prefixLetter></province><province><id>14</id><name>湖南</name><enName>HuNan</enName><prefixLetter>H</prefixLetter></province><province><id>15</id><name>吉林</name><enName>JiLin</enName><prefixLetter>J</prefixLetter></province><province><id>16</id><name>江苏</name><enName>JiangSu</enName><prefixLetter>J</prefixLetter></province><province><id>17</id><name>江西</name><enName>JiangXi</enName><prefixLetter>J</prefixLetter></province><province><id>18</id><name>辽宁</name><enName>LiaoNing</enName><prefixLetter>L</prefixLetter></province><province><id>19</id><name>内蒙古</name><enName>NeiMengGu</enName><prefixLetter>N</prefixLetter></province><province><id>20</id><name>宁夏</name><enName>NingXia</enName><prefixLetter>N</prefixLetter></province><province><id>21</id><name>青海</name><enName>QingHai</enName><prefixLetter>Q</prefixLetter></province><province><id>22</id><name>山东</name><enName>ShanDong</enName><prefixLetter>S</prefixLetter></province><province><id>23</id><name>山西</name><enName>ShanXi</enName><prefixLetter>S</prefixLetter></province><province><id>24</id><name>陕西</name><enName>ShanXi</enName><prefixLetter>S</prefixLetter></province><province><id>25</id><name>上海</name><enName>ShangHai</enName><prefixLetter>S</prefixLetter></province><province><id>26</id><name>四川</name><enName>SiChuan</enName><prefixLetter>S</prefixLetter></province><province><id>27</id><name>天津</name><enName>TianJin</enName><prefixLetter>T</prefixLetter></province><province><id>28</id><name>西藏</name><enName>Tibet</enName><prefixLetter>X</prefixLetter></province><province><id>29</id><name>新疆</name><enName>XinJiang</enName><prefixLetter>X</prefixLetter></province><province><id>30</id><name>云南</name><enName>YunNan</enName><prefixLetter>Y</prefixLetter></province><province><id>31</id><name>浙江</name><enName>ZheJiang</enName><prefixLetter>Z</prefixLetter></province><province><id>32</id><name>重庆</name><enName>ChongQing</enName><prefixLetter>C</prefixLetter></province><province><id>33</id><name>香港</name><enName>Hong Kong</enName><prefixLetter>X</prefixLetter></province><province><id>34</id><name>澳门</name><enName>Macao</enName><prefixLetter>A</prefixLetter></province><province><id>35</id><name>台湾</name><enName>Taiwan</enName><prefixLetter>T</prefixLetter></province></provinceList></body></response>";
		Document doc = DocumentHelper.parseText(provinceStr);
		Element rootElt = doc.getRootElement(); // 获取根节点

		// System.out.println("根节点：" + rootElt.getName());
		// System.out.println(rootElt.element("header").elementTextTrim("rspType"));

		Iterator iter = rootElt.element("body").element("provinceList").elementIterator("province");
		while (iter.hasNext()) {
			Element province = (Element) iter.next();
			String id = province.elementTextTrim("id");
			String name = province.elementTextTrim("name");
			String enName = province.elementTextTrim("enName");
			// System.out.println(id + "," + name + "," + enName.toLowerCase());

			// 城市
			String cityStr = getCityListByProvinceId(id);
			Document doc2 = DocumentHelper.parseText(cityStr);
			Element rootElt2 = doc2.getRootElement();
			if (rootElt2.element("body").element("cityList") == null) {
				continue;
			}
			Iterator iter2 = rootElt2.element("body").element("cityList").elementIterator("city");
			while (iter2.hasNext()) {
				Element city = (Element) iter2.next();
				String cityId = city.elementTextTrim("id");
				String cityName = city.elementTextTrim("name");
				String cityEnName = city.elementTextTrim("enName");
				// System.out.println("\t" + cityId + "," + cityName + "," +
				// cityEnName.toLowerCase());
				// System.out.println("update city set tongcheng_city_id="
				// + cityId + " where name like '" + cityName
				// + "%' or name_py='"
				// + cityEnName.toLowerCase().replace("'", "") + "'; ");

				// 行政区
				String areaStr = getAreaListByCityId(cityId);
				Document doc3 = DocumentHelper.parseText(areaStr);
				Element rootElt3 = doc3.getRootElement();
				if (rootElt3.element("body").element("countyList") != null) {
					Iterator iter3 = rootElt3.element("body").element("countyList").elementIterator("county");
					while (iter3.hasNext()) {
						Element county = (Element) iter3.next();
						String areaId = county.elementTextTrim("id");
						String areaName = county.elementTextTrim("name");
						String areaEnName = county.elementTextTrim("enName");
						System.out.println("insert into area_tongcheng(id,city_id,area_name,area_name_en) values("
								+ areaId + "," + cityId + ",'" + areaName + "','" + areaEnName + "');");
					}
				}

				// 商区
				String areaBizStr = getAreaBizListByCityId(cityId);
				Document doc4 = DocumentHelper.parseText(areaBizStr);
				Element rootElt4 = doc4.getRootElement();
				if (rootElt4.element("body").element("bizSectionList") != null) {
					Iterator iter4 = rootElt4.element("body").element("bizSectionList").elementIterator("bizSection");
					while (iter4.hasNext()) {
						Element countyBiz = (Element) iter4.next();
						String areaBizId = countyBiz.elementTextTrim("id");
						String areaBizName = countyBiz.elementTextTrim("name");
						System.out.println("insert into area_biz_tongcheng(id,city_id,area_biz_name) values("
								+ areaBizId + "," + cityId + ",'" + areaBizName + "');");
					}
				}

				// 连锁酒店
				String chainStr = getChainHotelList(cityId);
				Document doc5 = DocumentHelper.parseText(chainStr);
				Element rootElt5 = doc5.getRootElement(); // 获取根节点

				System.out.println("=" + cityId + "," + chainStr);
				System.out.println("==" + cityId + ","
						+ (rootElt5.element("body").elementIterator("chainList") != null));

				if (rootElt5.element("body").elementIterator("chainList") != null) {
					Iterator iter_chainList = rootElt5.element("body").elementIterator("chainList");
					while (iter_chainList.hasNext()) {
						Element chainList = (Element) iter_chainList.next();
						String chainType = chainList.attributeValue("type");

						System.out.println("===" + cityId + "," + chainType + ","
								+ (chainList.elementIterator("chain") != null));

						if (chainList.elementIterator("chain") != null) {
							Iterator iter_chain = chainList.elementIterator("chain");
							while (iter_chain.hasNext()) {
								Element chain = (Element) iter_chain.next();
								String chainId = chain.elementTextTrim("chainId");
								String chainName = chain.elementTextTrim("chainName");
								String shortName = chain.elementTextTrim("shortName");
								String photoUrl = chain.elementTextTrim("photoUrl");
								System.out
										.println("insert into city_chain_tongcheng(chain_id,city_id,chain_type,chain_name,short_name,photo_url) values("
												+ chainId
												+ ","
												+ cityId
												+ ","
												+ chainType
												+ ",'"
												+ chainName
												+ "','"
												+ shortName + "','" + photoUrl + "');");
							}
						}
					}
				}

			}
		}
	}

	private static String getOrderList(String mobile){
		Hashtable<String, String> ht = new Hashtable<String, String>(); // 将参数放入Hashtable中，便于操作
		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();

		SimpleDateFormat ymdhmsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String reqTime = ymdhmsf.format(date);

		ht.put("version", Constant.getCommonConf("tongcheng.version")); // 接口协议版本号，详见接口协议文档
		ht.put("accountId", Constant.getCommonConf("tongcheng.accountId")); // API帐户ID(小写)，待申请审批通过后发放
		ht.put("accountKey", Constant.getCommonConf("tongcheng.accountKey")); // API帐户密钥，待申请审批通过后发放
		ht.put("serviceName", "GetOrderList"); // 调用接口的方法名称
		ht.put("reqTime", reqTime); // 当前日期

		String url = "http://tcopenapi.17usoft.com/handlers/hotel/orderhandler.ashx"; // 请求URL地址

		StringBuilder strRequest = new StringBuilder(128); // 请求XML字符串
		strRequest.append("<?xml version='1.0' encoding='utf-8' standalone='yes'?>");
		strRequest.append("<request>");
		strRequest.append("<header>");
		strRequest.append("<version>" + ht.get("version") + "</version>");
		strRequest.append("<accountID>" + ht.get("accountId") + "</accountID>");
		strRequest.append("<serviceName>" + ht.get("serviceName") + "</serviceName>");
		try {
			strRequest.append("<digitalSign>" + TongchengUtil.createDigitalSign(ht) + "</digitalSign>");
		} catch (Exception e) {
			e.printStackTrace();
		}
		strRequest.append("<reqTime>" + ht.get("reqTime") + "</reqTime>");
		strRequest.append("</header>");
		strRequest.append("<body>");

		strRequest.append("<mobile>" + mobile + "</mobile>");
		strRequest.append("<orderType>1</orderType>");

		strRequest.append("</body>");
		strRequest.append("</request>");

		String strResponse = null;
		try {
			strResponse = TongchengUtil.callUrl(url, strRequest.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strResponse;
	}

	private static String getHotelRooms(String hotelId){
		Hashtable<String, String> ht = new Hashtable<String, String>(); // 将参数放入Hashtable中，便于操作
		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();

		SimpleDateFormat ymdhmsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String reqTime = ymdhmsf.format(date);

		ht.put("version", Constant.getCommonConf("tongcheng.version")); // 接口协议版本号，详见接口协议文档
		ht.put("accountId", Constant.getCommonConf("tongcheng.accountId")); // API帐户ID(小写)，待申请审批通过后发放
		ht.put("accountKey", Constant.getCommonConf("tongcheng.accountKey")); // API帐户密钥，待申请审批通过后发放
		ht.put("serviceName", "GetHotelRooms"); // 调用接口的方法名称
		ht.put("reqTime", reqTime); // 当前日期

		String url = "http://tcopenapi.17usoft.com/handlers/hotel/QueryHandler.ashx"; // 请求URL地址

		StringBuilder strRequest = new StringBuilder(128); // 请求XML字符串
		strRequest.append("<?xml version='1.0' encoding='utf-8' standalone='yes'?>");
		strRequest.append("<request>");
		strRequest.append("<header>");
		strRequest.append("<version>" + ht.get("version") + "</version>");
		strRequest.append("<accountID>" + ht.get("accountId") + "</accountID>");
		strRequest.append("<serviceName>" + ht.get("serviceName") + "</serviceName>");
		try {
			strRequest.append("<digitalSign>" + TongchengUtil.createDigitalSign(ht) + "</digitalSign>");
		} catch (Exception e) {
			e.printStackTrace();
		}
		strRequest.append("<reqTime>" + ht.get("reqTime") + "</reqTime>");
		strRequest.append("</header>");
		strRequest.append("<body>");

		strRequest.append("<hotelId>" + hotelId + "</hotelId>");
		strRequest.append("<comeDate>" + "2012-03-24" + "</comeDate>");
		strRequest.append("<leaveDate>" + "2012-03-28" + "</leaveDate>");
		strRequest.append("<page>1</page>");
		strRequest.append("<pageSize>100</pageSize>");

		strRequest.append("</body>");
		strRequest.append("</request>");

		String strResponse = null;
		try {
			strResponse = TongchengUtil.callUrl(url, strRequest.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strResponse;
	}

	private static String getHotelDetail(String hotelId){
		Hashtable<String, String> ht = new Hashtable<String, String>(); // 将参数放入Hashtable中，便于操作
		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();

		SimpleDateFormat ymdhmsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String reqTime = ymdhmsf.format(date);

		ht.put("version", Constant.getCommonConf("tongcheng.version")); // 接口协议版本号，详见接口协议文档
		ht.put("accountId", Constant.getCommonConf("tongcheng.accountId")); // API帐户ID(小写)，待申请审批通过后发放
		ht.put("accountKey", Constant.getCommonConf("tongcheng.accountKey")); // API帐户密钥，待申请审批通过后发放
		ht.put("serviceName", "GetHotelDetail"); // 调用接口的方法名称
		ht.put("reqTime", reqTime); // 当前日期

		String url = "http://tcopenapi.17usoft.com/handlers/hotel/QueryHandler.ashx"; // 请求URL地址

		StringBuilder strRequest = new StringBuilder(128); // 请求XML字符串
		strRequest.append("<?xml version='1.0' encoding='utf-8' standalone='yes'?>");
		strRequest.append("<request>");
		strRequest.append("<header>");
		strRequest.append("<version>" + ht.get("version") + "</version>");
		strRequest.append("<accountID>" + ht.get("accountId") + "</accountID>");
		strRequest.append("<serviceName>" + ht.get("serviceName") + "</serviceName>");
		try {
			strRequest.append("<digitalSign>" + TongchengUtil.createDigitalSign(ht) + "</digitalSign>");
		} catch (Exception e) {
			e.printStackTrace();
		}
		strRequest.append("<reqTime>" + ht.get("reqTime") + "</reqTime>");
		strRequest.append("</header>");
		strRequest.append("<body>");

		strRequest.append("<hotelId>" + hotelId + "</hotelId>");

		strRequest.append("</body>");
		strRequest.append("</request>");

		String strResponse = null;
		try {
			strResponse = TongchengUtil.callUrl(url, strRequest.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strResponse;
	}

	private static String getHotelList(String cityId){
		Hashtable<String, String> ht = new Hashtable<String, String>(); // 将参数放入Hashtable中，便于操作
		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();

		SimpleDateFormat ymdhmsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String reqTime = ymdhmsf.format(date);

		ht.put("version", Constant.getCommonConf("tongcheng.version")); // 接口协议版本号，详见接口协议文档
		ht.put("accountId", Constant.getCommonConf("tongcheng.accountId")); // API帐户ID(小写)，待申请审批通过后发放
		ht.put("accountKey", Constant.getCommonConf("tongcheng.accountKey")); // API帐户密钥，待申请审批通过后发放
		ht.put("serviceName", "GetHotelList"); // 调用接口的方法名称
		ht.put("reqTime", reqTime); // 当前日期

		String url = "http://tcopenapi.17usoft.com/handlers/hotel/QueryHandler.ashx"; // 请求URL地址

		StringBuilder strRequest = new StringBuilder(128); // 请求XML字符串
		strRequest.append("<?xml version='1.0' encoding='utf-8' standalone='yes'?>");
		strRequest.append("<request>");
		strRequest.append("<header>");
		strRequest.append("<version>" + ht.get("version") + "</version>");
		strRequest.append("<accountID>" + ht.get("accountId") + "</accountID>");
		strRequest.append("<serviceName>" + ht.get("serviceName") + "</serviceName>");
		try {
			strRequest.append("<digitalSign>" + TongchengUtil.createDigitalSign(ht) + "</digitalSign>");
		} catch (Exception e) {
			e.printStackTrace();
		}
		strRequest.append("<reqTime>" + ht.get("reqTime") + "</reqTime>");
		strRequest.append("</header>");
		strRequest.append("<body>");

		strRequest.append("<clientIp>212.222.55.12</clientIp>");
		strRequest.append("<cityId>" + cityId + "</cityId>");
		strRequest.append("<page>" + 1 + "</page>");
		strRequest.append("<pageSize>" + 3 + "</pageSize>");
		strRequest.append("<comeDate>" + "2012-03-26" + "</comeDate>");
		strRequest.append("<leaveDate>" + "2012-03-27" + "</leaveDate>");
		strRequest.append("<priceRange>,150</priceRange>");

		// if (key != null && !"".equals(key.trim())) {
		// strRequest.append("<keyword>" + key.trim() + "</keyword>");
		// strRequest.append("<searchFields>hotelName,address</searchFields>");
		// }
		//
		// if (priceRange != null && !"".equals(priceRange)) {
		// strRequest.append("<priceRange>" + priceRange + "</priceRange>");
		// }
		//
		// if (area != null && !"".equals(area)) {
		// strRequest.append("<sectionId>" + area + "</sectionId>");
		// }
		//
		// if (areaBiz != null && !"".equals(areaBiz)) {
		// strRequest.append("<bizSectionId>" + areaBiz + "</bizSectionId>");
		// }
		//
		// if (chain != null && !"".equals(chain)) {
		// strRequest.append("<chainId>" + chain + "</chainId>");
		// }

		strRequest.append("</body>");
		strRequest.append("</request>");

		String strResponse = null;
		try {
			strResponse = TongchengUtil.callUrl(url, strRequest.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strResponse;
	}

	private static String getChainHotelList(String cityId){
		Hashtable<String, String> ht = new Hashtable<String, String>(); // 将参数放入Hashtable中，便于操作

		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();

		SimpleDateFormat ymdhmsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String reqTime = ymdhmsf.format(date);

		ht.put("version", "20111128102912"); // 接口协议版本号，详见接口协议文档
		ht.put("accountId", "1b2af1d6-86d7-415b-8d23-8c3a3aa42c8c"); // API帐户ID(小写)，待申请审批通过后发放
		ht.put("accountKey", "581a4f7e29946cbf"); // API帐户密钥，待申请审批通过后发放
		ht.put("serviceName", "GetChainHotelList"); // 调用接口的方法名称
		ht.put("reqTime", reqTime); // 当前日期

		String url = "http://tcopenapi.17usoft.com/handlers/hotel/QueryHandler.ashx"; // 请求URL地址

		String strRequest = ""; // 请求XML字符串
		strRequest = strRequest + "<?xml version='1.0' encoding='utf-8' standalone='yes'?>";
		strRequest = strRequest + "<request>";
		strRequest = strRequest + "<header>";
		strRequest = strRequest + "<version>" + ht.get("version") + "</version>";
		strRequest = strRequest + "<accountID>" + ht.get("accountId") + "</accountID>";
		strRequest = strRequest + "<serviceName>" + ht.get("serviceName") + "</serviceName>";
		try {
			strRequest = strRequest + "<digitalSign>" + TongchengUtil.createDigitalSign(ht) + "</digitalSign>";
		} catch (Exception ex) {

			ex.printStackTrace();
		}
		strRequest = strRequest + "<reqTime>" + ht.get("reqTime") + "</reqTime>";
		strRequest = strRequest + "</header>";
		strRequest = strRequest + "<body>";

		strRequest = strRequest + "<chainType>1,4,5</chainType>";
		strRequest = strRequest + "<cityId>" + cityId + "</cityId>";

		strRequest = strRequest + "</body>";
		strRequest = strRequest + "</request>";

		String strResponse = null;
		try {
			strResponse = TongchengUtil.callUrl(url, strRequest);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strResponse;
	}

	private static String getAreaBizListByCityId(String cityId){
		Hashtable<String, String> ht = new Hashtable<String, String>(); // 将参数放入Hashtable中，便于操作

		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();

		SimpleDateFormat ymdhmsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String reqTime = ymdhmsf.format(date);

		ht.put("version", "20111128102912"); // 接口协议版本号，详见接口协议文档
		ht.put("accountId", "1b2af1d6-86d7-415b-8d23-8c3a3aa42c8c"); // API帐户ID(小写)，待申请审批通过后发放
		ht.put("accountKey", "581a4f7e29946cbf"); // API帐户密钥，待申请审批通过后发放
		ht.put("serviceName", "GetBizSectionList"); // 调用接口的方法名称
		ht.put("reqTime", reqTime); // 当前日期

		String url = "http://tcopenapi.17usoft.com/handlers/hotel/QueryHandler.ashx"; // 请求URL地址ַ

		String strRequest = ""; // 请求XML字符串
		strRequest = strRequest + "<?xml version='1.0' encoding='utf-8' standalone='yes'?>";
		strRequest = strRequest + "<request>";
		strRequest = strRequest + "<header>";
		strRequest = strRequest + "<version>" + ht.get("version") + "</version>";
		strRequest = strRequest + "<accountID>" + ht.get("accountId") + "</accountID>";
		strRequest = strRequest + "<serviceName>" + ht.get("serviceName") + "</serviceName>";
		try {
			strRequest = strRequest + "<digitalSign>" + TongchengUtil.createDigitalSign(ht) + "</digitalSign>";
		} catch (Exception ex) {

			ex.printStackTrace();
		}
		strRequest = strRequest + "<reqTime>" + ht.get("reqTime") + "</reqTime>";
		strRequest = strRequest + "</header>";
		strRequest = strRequest + "<body>";

		strRequest = strRequest + "<cityId>" + cityId + "</cityId>";

		strRequest = strRequest + "</body>";
		strRequest = strRequest + "</request>";

		String strResponse = null;
		try {
			strResponse = TongchengUtil.callUrl(url, strRequest);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strResponse;
	}

	private static String getAreaListByCityId(String cityId){
		Hashtable<String, String> ht = new Hashtable<String, String>(); // 将参数放入Hashtable中，便于操作

		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();

		SimpleDateFormat ymdhmsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String reqTime = ymdhmsf.format(date);

		ht.put("version", "20111128102912"); // 接口协议版本号，详见接口协议文档
		ht.put("accountId", "1b2af1d6-86d7-415b-8d23-8c3a3aa42c8c"); // API帐户ID(小写)，待申请审批通过后发放
		ht.put("accountKey", "581a4f7e29946cbf"); // API帐户密钥，待申请审批通过后发放
		ht.put("serviceName", "GetCountyListByCityId"); // 调用接口的方法名称
		ht.put("reqTime", reqTime); // 当前日期

		String url = "http://tcopenapi.17usoft.com/Handlers/General/AdministrativeDivisionsHandler.ashx"; // 请求URL地址ַ

		String strRequest = ""; // 请求XML字符串
		strRequest = strRequest + "<?xml version='1.0' encoding='utf-8' standalone='yes'?>";
		strRequest = strRequest + "<request>";
		strRequest = strRequest + "<header>";
		strRequest = strRequest + "<version>" + ht.get("version") + "</version>";
		strRequest = strRequest + "<accountID>" + ht.get("accountId") + "</accountID>";
		strRequest = strRequest + "<serviceName>" + ht.get("serviceName") + "</serviceName>";
		try {
			strRequest = strRequest + "<digitalSign>" + TongchengUtil.createDigitalSign(ht) + "</digitalSign>";
		} catch (Exception ex) {

			ex.printStackTrace();
		}
		strRequest = strRequest + "<reqTime>" + ht.get("reqTime") + "</reqTime>";
		strRequest = strRequest + "</header>";
		strRequest = strRequest + "<body>";

		strRequest = strRequest + "<cityId>" + cityId + "</cityId>";

		strRequest = strRequest + "</body>";
		strRequest = strRequest + "</request>";

		String strResponse = null;
		try {
			strResponse = TongchengUtil.callUrl(url, strRequest);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strResponse;
	}

	private static String getCityListByProvinceId(String provinceId){
		Hashtable<String, String> ht = new Hashtable<String, String>(); // 将参数放入Hashtable中，便于操作

		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();

		SimpleDateFormat ymdhmsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String reqTime = ymdhmsf.format(date);

		ht.put("version", "20111128102912"); // 接口协议版本号，详见接口协议文档
		ht.put("accountId", "1b2af1d6-86d7-415b-8d23-8c3a3aa42c8c"); // API帐户ID(小写)，待申请审批通过后发放
		ht.put("accountKey", "581a4f7e29946cbf"); // API帐户密钥，待申请审批通过后发放
		ht.put("serviceName", "GetCityListByProvinceId"); // 调用接口的方法名称
		ht.put("reqTime", reqTime); // 当前日期

		String url = "http://tcopenapi.17usoft.com/Handlers/General/AdministrativeDivisionsHandler.ashx"; // 请求URL地址ַ

		String strRequest = ""; // 请求XML字符串
		strRequest = strRequest + "<?xml version='1.0' encoding='utf-8' standalone='yes'?>";
		strRequest = strRequest + "<request>";
		strRequest = strRequest + "<header>";
		strRequest = strRequest + "<version>" + ht.get("version") + "</version>";
		strRequest = strRequest + "<accountID>" + ht.get("accountId") + "</accountID>";
		strRequest = strRequest + "<serviceName>" + ht.get("serviceName") + "</serviceName>";
		try {
			strRequest = strRequest + "<digitalSign>" + TongchengUtil.createDigitalSign(ht) + "</digitalSign>";
		} catch (Exception ex) {

			ex.printStackTrace();
		}
		strRequest = strRequest + "<reqTime>" + ht.get("reqTime") + "</reqTime>";
		strRequest = strRequest + "</header>";
		strRequest = strRequest + "<body>";

		strRequest = strRequest + "<provinceId>" + provinceId + "</provinceId>";

		strRequest = strRequest + "</body>";
		strRequest = strRequest + "</request>";

		String strResponse = null;
		try {
			strResponse = TongchengUtil.callUrl(url, strRequest);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return strResponse;
	}

	private static void test1(){
		Hashtable<String, String> ht = new Hashtable<String, String>(); // 将参数放入Hashtable中，便于操作

		Calendar calendar = Calendar.getInstance();
		Date date = calendar.getTime();

		SimpleDateFormat ymdhmsf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
		String reqTime = ymdhmsf.format(date);

		ht.put("version", "20111128102912"); // 接口协议版本号，详见接口协议文档
		ht.put("accountId", "1b2af1d6-86d7-415b-8d23-8c3a3aa42c8c"); // API帐户ID(小写)，待申请审批通过后发放
		ht.put("accountKey", "581a4f7e29946cbf"); // API帐户密钥，待申请审批通过后发放
		ht.put("serviceName", "GetProvinceList"); // 调用接口的方法名称
		ht.put("reqTime", reqTime); // 当前日期

		String url = "http://tcopenapi.17usoft.com/Handlers/General/AdministrativeDivisionsHandler.ashx"; // 请求URL地址ַ

		String strRequest = ""; // 请求XML字符串
		strRequest = strRequest + "<?xml version='1.0' encoding='utf-8' standalone='yes'?>";
		strRequest = strRequest + "<request>";
		strRequest = strRequest + "<header>";
		strRequest = strRequest + "<version>" + ht.get("version") + "</version>";
		strRequest = strRequest + "<accountID>" + ht.get("accountId") + "</accountID>";
		strRequest = strRequest + "<serviceName>" + ht.get("serviceName") + "</serviceName>";
		try {
			strRequest = strRequest + "<digitalSign>" + TongchengUtil.createDigitalSign(ht) + "</digitalSign>";
		} catch (Exception ex) {

			ex.printStackTrace();
		}
		strRequest = strRequest + "<reqTime>" + ht.get("reqTime") + "</reqTime>";
		strRequest = strRequest + "</header>";
		strRequest = strRequest + "<body>";

		// ***将参数param1注释即可看到少传参数返回的错误信息显示***
		// strRequest = strRequest + "<param1>example</param1>";
		// strRequest = strRequest + "<param2>1</param2>";

		// strRequest = strRequest + "<param2>1</param2>";

		strRequest = strRequest + "</body>";
		strRequest = strRequest + "</request>";

		try {
			String strResponse = TongchengUtil.callUrl(url, strRequest);
			System.out.println(strResponse);

		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
